//
//  RegistrationViewController.m
//  安好
//
//  Created by lianchuang on 14-11-10.
//  Copyright (c) 2014年 lianchuangbrother. All rights reserved.
//

#import "RegistrationViewController.h"
#import "RegistrationCell.h"
#import "QuickRegViewController.h"
#import "ClassifyRegViewController.h"
#import "TeXuRegViewController.h"
#import "RegistrationfirstPicCell.h"
#import "GuahaoRecordViewController.h"

#define RGB(r, g, b)    [UIColor colorWithRed:(r)/255.f green:(g)/255.f blue:(b)/255.f alpha:1.f]

#define iPhone6Plus ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(1242, 2208), [[UIScreen mainScreen] currentMode].size) : NO)

@interface RegistrationViewController ()<UITableViewDataSource,UITableViewDelegate>

@end

@implementation RegistrationViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self makeNavBar];
    [self loadData];
    [self makeTableView];
}
#pragma mark - 导航条设置
-(void)makeNavBar
{
    self.navigationItem.title = @"挂号";
    //左按钮--返回
    UIBarButtonItem *backBtnImg = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"公用_返回.png"] style:UIBarButtonItemStylePlain target:self action:@selector(backClicked)];
    [backBtnImg setTintColor:[UIColor whiteColor]];
    self.navigationItem.leftBarButtonItem = backBtnImg;
    //右按钮-- “挂号记录”
    UIBarButtonItem *recordBtnImg = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"发现_挂号病单.png"] style:UIBarButtonItemStylePlain target:self action:@selector(recordBtnClicked)];
    [recordBtnImg setTintColor:[UIColor whiteColor]];
    self.navigationItem.rightBarButtonItem = recordBtnImg;
    //发现_挂号病单
}
/**
 * 返回
 */
-(void)backClicked
{
    [self.navigationController popViewControllerAnimated:YES];
}

/**
 *  触发进入 挂号记录--上传挂号单 先判断是否登录了
 */
-(void)recordBtnClicked
{
    [self isLogin];
}
- (void)Login{
    
    GuahaoRecordViewController * guahao = [[GuahaoRecordViewController alloc] init];
    [self.navigationController pushViewController:guahao animated:YES];
    
    
}

#pragma mark - 加载数据
-(void)loadData
{
   self.registrationTypes = @[@"快速挂号",@"分类挂号",@"特需挂号"];
}
#pragma mark - 创建tableView 设置代理添加头视图
-(void)makeTableView
{
    self.tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, kScreenHeight-iOS7TopMargin)style:UITableViewStyleGrouped];
    [self.view addSubview:self.tableView];
    self.tableView.backgroundColor = [ClassMethodsViewController colorWithHexString:BACK_BACKGROUNDCOLOR_16];
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    //隐藏横向和竖向的滑条
    self.tableView.showsHorizontalScrollIndicator = NO;
    self.tableView.showsVerticalScrollIndicator = NO;

    [self.tableView setSeparatorColor:[UIColor colorWithRed:221/255.0 green:221/255.0 blue:221/255.0 alpha:1]];
    
}

#pragma mark - tableView的代理方法

-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 2;
}
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    if (section == 0) {
        return 0.01;
    }else
    {
        if (iPhone6Plus) {
            return 12;
        }else{
            return 10;
        }
    }
}
-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
    return 0.01;
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.section == 0) {
        if (iPhone6Plus) {
            return 120;
        }else{
            return 100;
        }
    }else
    {
        if (iPhone6Plus) {
            return 53;
        }else{
            return 44;
        }
    }
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    if (section == 0) {
        return 1;
    }else{
        return self.registrationTypes.count;
    }
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.section == 0) {
        RegistrationfirstPicCell * cell  = [tableView dequeueReusableCellWithIdentifier:@"PicCell"];
        if (cell == nil) {
            if (iPhone6Plus) {
                cell = [[[NSBundle mainBundle] loadNibNamed:@"RegistrationfirstPicCell" owner:self options:nil] lastObject];
            }else{
                cell = [[[NSBundle mainBundle] loadNibNamed:@"RegistrationfirstPicCell" owner:self options:nil] lastObject];
            }
        }
        
        [cell.regPicImg setImage:[UIImage imageNamed:@"挂号-bannner.png"]];
        
        return cell;
        
    }else{
    
        RegistrationCell *cell = [tableView dequeueReusableCellWithIdentifier:@"ID"];
    
        if (cell == nil) {
       
            if (iPhone6Plus) {
                cell = [[[NSBundle mainBundle] loadNibNamed:@"RegistrationCell" owner:self options:nil] lastObject];
            }else{
                cell = [[[NSBundle mainBundle] loadNibNamed:@"RegistrationCell" owner:self options:nil] firstObject];
            }
        }
        cell.registrationLable.text = self.registrationTypes[indexPath.row];
        UIImage * jumpImg = [UIImage imageNamed:@"公用_跳转.png"];
        [cell.accessoryTypeImgView setImage:jumpImg];
        cell.accessoryTypeImgView.frame = CGRectMake(kScreenWidth-(15+jumpImg.size.width), (cell.contentView.height-jumpImg.size.height)/2.0, jumpImg.size.width,jumpImg.size.height);
        if (iPhone6Plus) {
            cell.registrationLable.left = 20;
            cell.accessoryTypeImgView.right = kScreenWidth - 20;
        }
        return cell;
    }
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.section == 0) {
        if (indexPath.row == 0) {
            [self recordBtnClicked];
        }
    }else{
    if (indexPath.row == 0){
        QuickRegViewController * quickViewController = [[QuickRegViewController alloc]init];
        [self.navigationController pushViewController:quickViewController animated:YES];
    }
    if (indexPath.row == 1) {
        ClassifyRegViewController * classify = [[ClassifyRegViewController alloc] init];
        [self.navigationController pushViewController:classify animated:YES];
    }
    if (indexPath.row == 2) {
        TeXuRegViewController * texu = [[TeXuRegViewController alloc] init];
        [self.navigationController pushViewController:texu animated:YES];
    }
        
    }
}

@end
